package com.cby.android.sample.adapter

import android.app.Activity
import android.content.Intent
import com.cby.android.library.utils.ZxingScanUtils
import com.cby.android.sample.R
import com.cby.android.sample.activities.*
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import java.util.*

/**
 * @description: RollMoreItemAdapter
 *
 * @author ChenBaoyang
 * @date 4/23/21 11:28
 */
class RollMoreItemAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.roll_item_more_item) {

    private val titleIconMap: HashMap<String, Int> =
        object : HashMap<String, Int>() {
            init {
                put("垃圾分类", R.drawable.gank_icon_tools_rubbish)
                put("新华字典", R.drawable.gank_icon_tools_zidian)
                put("历史上的今天", R.drawable.gank_icon_tools_history)
                put("周公解梦", R.drawable.gank_icon_tools_zhougong)
                put("婚姻匹配", R.drawable.gank_icon_tools_hunyin)
                put("八字算命", R.drawable.gank_icon_tools_suanming)
                put("老黄历", R.drawable.gank_icon_tools_huangli)
                put("手机号码归属地", R.drawable.gank_icon_tools_phone_address)
                put("IP地址", R.drawable.gank_icon_tools_ip)
                put("世界电话区号", R.drawable.gank_icon_tools_phone_code)
                put("扫一扫", R.drawable.gank_icon_tools_scan)
                put("扫码记录", R.drawable.gank_icon_tools_scan_history)
                put("二维码生成", R.drawable.gank_icon_tools_scancode)
                put("笑话段子", R.drawable.gank_icon_tools_smile)
            }
        }

    override fun convert(holder: BaseViewHolder, item: String) {
        holder.setText(R.id.tv_title_more_item, item)
        val iconMap: Int? = titleIconMap[item]
        holder.setImageResource(R.id.iv_more_item, iconMap ?: R.drawable.gank_icon_more_tools)

        holder.itemView.setOnClickListener {

            when (item) {
                "手机号码归属地" -> {
                    context.startActivity(Intent(context, RollPhoneAddressActivity::class.java))
                }
                "扫一扫" -> {
                    ZxingScanUtils.open(context as Activity)
                }
                "扫码记录" -> {
                    //context.startActivity(Intent(context, ScanResultActivity::class.java))
                }
                "IP地址" -> {
                    context.startActivity(Intent(context, RollIpQueryActivity::class.java))
                }
                "周公解梦" -> {
                    openWebPage(
                        context,
                        "工具",
                        "周公解梦",
                        "http://tools.2345.com/zhgjm.htm"
                    )
                }
                "婚姻匹配" -> {
                    openWebPage(
                        context,
                        "工具",
                        "婚姻匹配",
                        "http://www.jjdzc.com/peidui/hehun.html"
                    )
                }
                "八字算命" -> {
                    openWebPage(
                        context,
                        "工具",
                        "八字算命",
                        "http://www.jjdzc.com/sm/bz.html"
                    )
                }
                "老黄历" -> {
                    //context.startActivity(Intent(context, ChineseCalendarActivity::class.java))
                }
                "垃圾分类" -> {
                    context.startActivity(Intent(context, RollRubbishActivity::class.java))
                }
                "历史上的今天" -> {
                    context.startActivity(Intent(context, RollHistoryTodayActivity::class.java))
                }
                "世界电话区号" -> {
                    context.startActivity(Intent(context, RollWorldPhoneCodeActivity::class.java))
                }
                "新华字典" -> {
                    context.startActivity(Intent(context, RollDictionaryActivity::class.java))
                }
                "笑话段子" -> {
                    context.startActivity(Intent(context, RollJokeActivity::class.java))
                }
                "二维码生成" -> {
                    context.startActivity(Intent(context, RollQRCodeActivity::class.java))
                }
            }
        }
    }
}